using System;
using System.Windows;
using DeSleeper.Client.Installation;

namespace DeSleeper.Client.Service
{
    internal class ConfigureTargetsParameters : Freezable
    {
        #region TargetsString Dependency Property
        /// <summary>
        /// A comma separated list of hosts to configure.
        /// </summary>
        public string TargetsString
        {
            get { return (string) GetValue(TargetsStringProperty); }
            set { SetValue(TargetsStringProperty, value); }
        }

        /// <summary>
        /// <see cref="TargetsString"/> Dependency Property.
        /// </summary>
        public static readonly DependencyProperty TargetsStringProperty =
            DependencyProperty.Register(
                "TargetsString",
                typeof (string),
                typeof (ConfigureTargetsParameters),
                new PropertyMetadata(new PropertyChangedCallback(TargetsStringChanged)));

        private static void TargetsStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var parameters = d as ConfigureTargetsParameters;
            if (parameters != null)
            {
                parameters._targets = null;
            }
        }

        private InstallTargets _targets;
        public InstallTargets Targets
        {
            get
            {
                if (_targets == null)
                    _targets = new InstallTargets(TargetsString);
                return _targets;
            }
        }
        #endregion

        #region EnableWakeOnLan Dependency Property
        /// <summary>
        /// 
        /// </summary>
        public bool EnableWakeOnLan
        {
            get { return (bool) GetValue(EnableWakeOnLanProperty); }
            set { SetValue(EnableWakeOnLanProperty, value); }
        }

        /// <summary>
        /// <see cref="EnableWakeOnLan"/> Dependency Property.
        /// </summary>
        public static readonly DependencyProperty EnableWakeOnLanProperty =
            DependencyProperty.Register(
                "EnableWakeOnLan",
                typeof (bool),
                typeof (ConfigureTargetsParameters));
        #endregion

        #region ConfigurePowerSettings Dependency Property
        /// <summary>
        /// Should the power settings for the targets be set?
        /// </summary>
        public bool ConfigurePowerSettings
        {
            get { return (bool) GetValue(ConfigurePowerSettingsProperty); }
            set { SetValue(ConfigurePowerSettingsProperty, value); }
        }

        /// <summary>
        /// <see cref="ConfigurePowerSettings"/> Dependency Property.
        /// </summary>
        public static readonly DependencyProperty ConfigurePowerSettingsProperty =
            DependencyProperty.Register(
                "ConfigurePowerSettings",
                typeof (bool),
                typeof (ConfigureTargetsParameters));
        #endregion

        #region MaximumHardDriveTimeout Dependency Property
        /// <summary>
        /// A timespan to set the hard drive power save option to if it is currently
        /// higher.
        /// </summary>
        public TimeSpan? MaximumHardDriveTimeout
        {
            get { return (TimeSpan?) GetValue(MaximumHardDriveTimeoutProperty); }
            set { SetValue(MaximumHardDriveTimeoutProperty, value); }
        }

        /// <summary>
        /// <see cref="MaximumHardDriveTimeout"/> Dependency Property.
        /// </summary>
        public static readonly DependencyProperty MaximumHardDriveTimeoutProperty =
            DependencyProperty.Register(
                "MaximumHardDriveTimeout",
                typeof (TimeSpan?),
                typeof (ConfigureTargetsParameters));
        #endregion
        #region MaximumIdleTimeout Dependency Property
        /// <summary>
        /// A timespan to set the sleep timer to if it is currently higher.
        /// </summary>
        public TimeSpan? MaximumIdleTimeout
        {
            get { return (TimeSpan?) GetValue(MaximumIdleTimeoutProperty); }
            set { SetValue(MaximumIdleTimeoutProperty, value); }
        }

        /// <summary>
        /// <see cref="MaximumIdleTimeout"/> Dependency Property.
        /// </summary>
        public static readonly DependencyProperty MaximumIdleTimeoutProperty =
            DependencyProperty.Register(
                "MaximumIdleTimeout",
                typeof (TimeSpan?),
                typeof (ConfigureTargetsParameters));

        #endregion
        #region MaximumVideoTimeout Dependency Property
        /// <summary>
        /// A timespan to set the video power save option to if it is currently higher.
        /// </summary>
        public TimeSpan? MaximumVideoTimeout
        {
            get { return (TimeSpan?) GetValue(MaximumVideoTimeoutProperty); }
            set { SetValue(MaximumVideoTimeoutProperty, value); }
        }

        /// <summary>
        /// <see cref="MaximumVideoTimeout"/> Dependency Property.
        /// </summary>
        public static readonly DependencyProperty MaximumVideoTimeoutProperty =
            DependencyProperty.Register(
                "MaximumVideoTimeout",
                typeof (TimeSpan?),
                typeof (ConfigureTargetsParameters));
        #endregion
        
        protected override Freezable CreateInstanceCore()
        {
            return new ConfigureTargetsParameters();
        }
    }
}